import { mockRequestClient as requestClient } from '#/api/request';

enum Api {
  DeployApplication = '/resource-center/saas/applications/deploy',
  GetDeployStatus = '/resource-center/saas/applications/deploy/status',
  GetDeployLogs = '/resource-center/saas/applications/deploy/logs',
  CancelDeploy = '/resource-center/saas/applications/deploy/cancel',
  RollbackDeploy = '/resource-center/saas/applications/deploy/rollback',
}

export interface DeployConfig {
  applicationId: string;
  version: string;
  environment: 'dev' | 'staging' | 'prod';
  region: string;
  resources: {
    cpu: number;
    memory: number;
    storage: number;
  };
  domain?: string;
  envVars?: string;
  strategy: 'rolling' | 'blue-green' | 'canary';
}

export interface DeployStatus {
  id: string;
  applicationId: string;
  status: 'pending' | 'running' | 'success' | 'failed' | 'cancelled';
  currentStep: number;
  totalSteps: number;
  progress: number;
  startTime: string;
  endTime?: string;
  error?: string;
}

export interface DeployLog {
  id: string;
  deployId: string;
  timestamp: string;
  level: 'info' | 'success' | 'error' | 'warning';
  message: string;
  step: string;
}

// 部署应用
export const deployApplication = (config: DeployConfig) => {
  return requestClient.post(Api.DeployApplication, config);
};

// 获取部署状态
export const getDeployStatus = (deployId: string) => {
  return requestClient.get(`${Api.GetDeployStatus}/${deployId}`);
};

// 获取部署日志
export const getDeployLogs = (deployId: string) => {
  return requestClient.get(`${Api.GetDeployLogs}/${deployId}`);
};

// 取消部署
export const cancelDeploy = (deployId: string) => {
  return requestClient.post(`${Api.CancelDeploy}/${deployId}`);
};

// 回滚部署
export const rollbackDeploy = (deployId: string) => {
  return requestClient.post(`${Api.RollbackDeploy}/${deployId}`);
};
